package com.taobao.api.request;

import com.taobao.api.internal.util.RequestCheckUtils;
import java.util.Map;

import com.taobao.api.TaobaoRequest;
import com.taobao.api.internal.util.TaobaoHashMap;
import com.taobao.api.response.HanoiFunctionAddResponse;
import com.taobao.api.ApiRuleException;
/**
 * TOP API: taobao.hanoi.function.add request
 * 
 * @author auto create
 * @since 1.0, 2013-08-03 16:51:00
 */
public class HanoiFunctionAddRequest implements TaobaoRequest<HanoiFunctionAddResponse> {

	private Map<String, String> headerMap = new TaobaoHashMap();
	private TaobaoHashMap udfParams; // add user-defined text parameters
	private Long timestamp;

	/** 
	* 分配给调用方的名称信息，内部统计使用
	 */
	private String appName;

	/** 
	* 函数配置名称
	 */
	private String name;

	/** 
	* 函数规则类型 0：JSON 1：条件表达式
	 */
	private Long parseType;

	/** 
	* 函数规则定义。支持JSON格式，条件表达式等等。groupId：要匹配人群的标签Id。actionId：需要执行动作的动作Id。filterType：匹配类型。0代表动态标签 1代表标签组 doAction:true代表执行动作 getData:true 或者false true代表要匹配结果
	 */
	private String rule;

	/** 
	* 规则开放策略 0：user_id私有 1：所有user_id可以使用 2：同一创建者下的user_id拥有
	 */
	private Long strategy;

	public void setAppName(String appName) {
		this.appName = appName;
	}
	public String getAppName() {
		return this.appName;
	}

	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return this.name;
	}

	public void setParseType(Long parseType) {
		this.parseType = parseType;
	}
	public Long getParseType() {
		return this.parseType;
	}

	public void setRule(String rule) {
		this.rule = rule;
	}
	public String getRule() {
		return this.rule;
	}

	public void setStrategy(Long strategy) {
		this.strategy = strategy;
	}
	public Long getStrategy() {
		return this.strategy;
	}

	public Long getTimestamp() {
		return this.timestamp;
	}

	public void setTimestamp(Long timestamp) {
		this.timestamp = timestamp;
	}

	public String getApiMethodName() {
		return "taobao.hanoi.function.add";
	}

	public Map<String, String> getTextParams() {		
		TaobaoHashMap txtParams = new TaobaoHashMap();
		txtParams.put("app_name", this.appName);
		txtParams.put("name", this.name);
		txtParams.put("parse_type", this.parseType);
		txtParams.put("rule", this.rule);
		txtParams.put("strategy", this.strategy);
		if(this.udfParams != null) {
			txtParams.putAll(this.udfParams);
		}
		return txtParams;
	}

	public void putOtherTextParam(String key, String value) {
		if(this.udfParams == null) {
			this.udfParams = new TaobaoHashMap();
		}
		this.udfParams.put(key, value);
	}

	public Class<HanoiFunctionAddResponse> getResponseClass() {
		return HanoiFunctionAddResponse.class;
	}

	public void check() throws ApiRuleException {
		RequestCheckUtils.checkNotEmpty(appName,"appName");
		RequestCheckUtils.checkNotEmpty(name,"name");
		RequestCheckUtils.checkNotEmpty(parseType,"parseType");
		RequestCheckUtils.checkNotEmpty(rule,"rule");
		RequestCheckUtils.checkMaxLength(rule,1000,"rule");
		RequestCheckUtils.checkNotEmpty(strategy,"strategy");
	}

	public Map<String, String> getHeaderMap() {
		return headerMap;
	}
}
